package com.hps.demo.job;

import com.alibaba.fastjson.JSON;
import com.hps.demo.dto.OrderInitDTO;
import com.hps.demo.service.IGoodService;
import com.hps.demo.service.IOrderService;
import com.hps.demo.service.IUserService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import javax.annotation.Resource;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

/**
 *
 * @author heps
 * @since 2020/10/28
 */
@Component
public class DataInitTask {

  @Resource
  private IGoodService goodService;

  @Resource
  private IUserService userService;

  @Resource
  private IOrderService orderService;

  @XxlJob("goodInitHandler")
  public ReturnT<String> initGood(String param) {
    int count = Integer.parseInt(param);
    goodService.initData(count);
    return ReturnT.SUCCESS;
  }

  @XxlJob("userInitHandler")
  public ReturnT<String> initUser(String param) {
    int count = Integer.parseInt(param);
    userService.initData(count);
    return ReturnT.SUCCESS;
  }

  @XxlJob("orderInitHandler")
  public ReturnT<String> initOrder(String param) {
    OrderInitDTO orderInitDTO = JSON.parseObject(param, OrderInitDTO.class);
    orderService.initData(orderInitDTO);
    return ReturnT.SUCCESS;
  }

  @XxlJob("reduceNoOrderUserHandler")
  public ReturnT<String> reduceNoOrderUserHandler(String param) {
    OrderInitDTO orderInitDTO = JSON.parseObject(param, OrderInitDTO.class);
    orderService.reduceNoOrderUser(orderInitDTO);
    return ReturnT.SUCCESS;
  }
}
